﻿// -----------------------------------------------------------------------
// <copyright file="Global.asax.cs" company="EPAM Systems">
////Copyright (c) EPAM Systems. All rights reserved.
// </copyright>
// -----------------------------------------------------------------------

namespace Epam.PhotoGallery.Site
{
	using System.Web.Mvc;
	using System.Web.Routing;
    using Epam.PhotoGallery.Interfaces.DataTransferObjects;
    using Epam.PhotoGallery.Site.CustomModelBinders;

	/// <summary>
	/// Mvc application
	/// </summary>
	public class MvcApplication : System.Web.HttpApplication
	{
		/// <summary>
		/// Registers the routes.
		/// </summary>
		/// <param name="routes">The routes.</param>
		public static void RegisterRoutes(RouteCollection routes)
		{
			routes.IgnoreRoute("{resource}.axd/{*pathInfo}");
			routes.IgnoreRoute("{resource}.ashx/{*pathInfo}");

          
            routes.MapRoute("GetImage", "Repository/Albums/Images/{id}.jpeg", new { controller = "Gallery", action = "GetImage" });

            routes.MapRoute("GetCover", "Repository/Cover/Images/{id}.jpeg", new { controller = "Gallery", action = "GetCover" });

            routes.MapRoute("GetControlImage", "Repository/Control/Images/{id}.jpeg", new { controller = "Gallery", action = "GetControlImage" });

            routes.MapRoute("BookDetails", "{controller}/Book/{isbnID}", new { controller = "Library", action = "GetBookDetails" }, new { isbnID = @"\d+" });

            routes.MapRoute("MainLibrary", "Library/", new { controller = "Library", action = "Index", page = 1 }, new { page = @"\d+" });

            routes.MapRoute("PageLibrary", "Library/page/{page}", new { controller = "Library", action = "Index" }, new { page = @"\d+" });

            routes.MapRoute("TopicCreation", "{controller}/Category/{categoryID}/TopicCreation", new { controller = "Community", action = "CreateTopic"});

            routes.MapRoute("CommunityCategory", "{controller}/Category/{categoryID}", new { controller = "Community", action = "GetTopicsFromCategory" });

            routes.MapRoute("Gallery", "{controller}/{action}/{isUpdate}", new { controller = "Gallery", action = "Index", isUpdate = false/*, UrlParameter.Optional*/ });

            routes.MapRoute("Community", "{controller}/", new { controller = "Community", action = "Index" });

            routes.MapRoute("Main", "{controller}/{action}", new { controller = "Office", action = "Index" });
		}

		/// <summary>
		/// Application_s the start.
		/// </summary>
		protected void Application_Start()
		{
			AreaRegistration.RegisterAllAreas();
			RegisterRoutes(RouteTable.Routes);
            ModelBinders.Binders.Add(typeof(Category), new CategoryModelBinder());
            ModelBinders.Binders.Add(typeof(Topic), new TopicModelBinder());
            ModelBinders.Binders.Add(typeof(Comment), new CommentModelBinder());
		}
	}
}
